<?php
namespace App\Http\Controllers\ShopApi\V1\DoubleCalendar;

use App\Http\Controllers\ShopApiController;
use App\Http\Controllers\Business\Shop\V1\DoubleCalendar\DoubleCalendar;

class DoubleCalendarController extends ShopApiController
{
    //设置翻贝日
    public function setDoubleCalendar() {
        $shopUserId = $this->shopUserId;
        $shopId = $this->request->get('shopid');
        $eventJson = $this->request->get('event');
        $event = json_decode($eventJson, true);
        $result = DoubleCalendar::setDoubleCalendar($shopId, $event, $shopUserId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        return $this->responseSuccessMessage($result['message']);
    }
    //获取翻贝日
    public function getDoubleCalendar() {
        $shopId = $this->request->get('shopid');
        $result = DoubleCalendar::getDoubleCalendar($shopId);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = [];
        $lists = $result['data'];
        foreach($lists as $list) {
            $event = $list['event'];
            array_push($data, date('Y-m-d', strtotime($event)));
        }
        return $this->responseSuccessData($data);
    }
    //设置晚九点
    public function setNightEvent() {
        $shopId = $this->request->get('shopid');
        $type = $this->request->get('type'); //type为0 表示关闭晚场， 1表示开启晚场
        $result = DoubleCalendar::nightShow($shopId, $type);
        if($result['status'] == 'failed') {
            return $this->responseError($result['message']);
        }
        $data = ['type'=>$type];
        return $this->responseSuccessData($data);
    }
}